package c.x.jy.service.service.impl;

import c.x.jy.dao.dto.OrderBillEntityDto;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.Query;

import c.x.jy.dao.dao.OrderBillDao;
import c.x.jy.dao.entity.OrderBillEntity;
import c.x.jy.service.service.OrderBillService;
import org.apache.commons.lang3.StringUtils;


@Service("orderBillService")
public class OrderBillServiceImpl extends ServiceImpl<OrderBillDao, OrderBillEntity> implements OrderBillService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        	QueryWrapper<OrderBillEntity> query= 	 new QueryWrapper<OrderBillEntity>() ;
    	if(params.get("searchKey")!=null&&params.get("searchValue")!=null&&!StringUtils.isEmpty(params.get("searchKey").toString())&&!StringUtils.isEmpty(params.get("searchValue").toString()))
    	    query.eq(  params.get("searchKey").toString(), params.get("searchValue"));
        if(params.get("businessId")!=null) 	query.eq("business_id", params.get("businessId"));
        if(params.get("orderId")!=null)query.eq("order_id",params.get("orderId"));
//        IPage<OrderBillEntity> page = this.page(
//                new Query<OrderBillEntity>().getPage(params),
//                 query
//        );
        IPage<OrderBillEntityDto> page =   this.getBaseMapper().querypage(new Query<OrderBillEntity>().getPage(params),  query);

        return new PageUtils(page);
    }

    @Override
    public OrderBillEntity selectByOrderNo(String orderNo) {
        QueryWrapper<OrderBillEntity> query=new QueryWrapper<>();
        query.lambda().eq(OrderBillEntity::getOrderNo,orderNo);
        return this.baseMapper.selectOne(query);
    }

	@Override
	public OrderBillEntity selectByorderForUpdate(Long id) {
		// TODO Auto-generated method stub
		return this.baseMapper.selectByorderForUpdate(id);
	}

}
